package models

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

// UserRequest 登录和注册请求
type UserRequest struct {
	UserName string `form:"username" json:"username" binding:"required"`
	Password string `form:"password" json:"password" binding:"required"`
}

// UserInfoRequest 用户信息请求
type UserInfoRequest struct {
	UserId int64  `form:"user_id" json:"user_id" binding:"required"`
	Token  string `form:"token" json:"token" binding:"required"`
}

// UserResponse 登录和注册响应
type UserResponse struct {
	Response
	UserId int64  `json:"user_id,omitempty"`
	Token  string `json:"token"`
}

// UserInfoResponse 用户信息响应
type UserInfoResponse struct {
	Response
	User `json:"user"`
}

// ResponseUserError 用户操作错误
func ResponseUserError(c *gin.Context, code ResCode) {
	c.JSON(http.StatusOK, &UserResponse{
		Response: Response{StatusCode: code, StatusMsg: code.Msg()},
		UserId:   -1,
		Token:    "",
	})
}

// ResponseUserSuccess 用户操作成功
func ResponseUserSuccess(c *gin.Context, userId int64, token string) {
	c.JSON(http.StatusOK, &UserResponse{
		Response: Response{StatusCode: CodeSuccess, StatusMsg: ResCode.Msg(CodeSuccess)},
		UserId:   userId,
		Token:    token,
	})
}

// ResponseUserInfoSuccess 用户信息操作成功
func ResponseUserInfoSuccess(c *gin.Context, user User) {
	c.JSON(http.StatusOK, &UserInfoResponse{
		Response: Response{StatusCode: CodeSuccess, StatusMsg: ResCode.Msg(CodeSuccess)},
		User:     user,
	})
}

// ResponseUserInfoError 用户信息操作失败
func ResponseUserInfoError(c *gin.Context, code ResCode) {
	c.JSON(http.StatusOK, &UserInfoResponse{
		Response: Response{StatusCode: code, StatusMsg: code.Msg()},
	})
}
